package me.zhengjie.poemQuestions.domain.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;

public enum QuestionType {
    SINGLE_CHOICE("single_choice"),  //单选题
    FILL_BLANK   ("fill_blank"); //填空题

    // 标记这是要写入到数据库的字段
    @EnumValue
    private final String value;

    QuestionType(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }

    /**
     * 根据数据库存储值反序列化
     */
    public static QuestionType fromValue(String dbValue) {
        for (QuestionType t : values()) {
            if (t.value.equalsIgnoreCase(dbValue)) {
                return t;
            }
        }
        throw new IllegalArgumentException("Unknown QuestionType: " + dbValue);
    }
}
